<?php
/**
 * Created by PhpStorm.
 * User: admin
 * Date: 2019/6/5
 * Time: 15:51
 */

namespace app\mobile\controller;

use app\admin\model\CategoryList;
use app\admin\model\CommonInfo;
use app\admin\model\DesignerList;
use app\admin\model\LeaveWord;
use app\admin\model\ListsList;
use app\admin\model\LunboList;
use app\admin\model\NewsList;
use app\admin\model\ProcessList;
use think\Controller;

class Index extends Base
{

    public function index()
    {
        $cate = CategoryList::where('id',2)->find();
        $lunbo = LunboList::where('category_id',2)->order('sort desc')->select();
        $foot = CommonInfo::where('id',1)->find();
        $news = CategoryList::where('id',12)->find();
        $lists = CategoryList::where('id',10)->find();
        $designer = CategoryList::where('id',13)->find();
        $news['list'] = NewsList::where('is_home',1)->limit(4)->select();
        $lists['list'] = ListsList::where('is_home',1)->limit(4)->select();
        $designer['list'] = DesignerList::where('is_home',1)->limit(4)->select();
        $processData=ProcessList::order('sort desc')->select();
        $allarr=array();
        for($i=0;$i<$processData->count();$i=$i+2){
            if(($i+1)<$processData->count()){
                $arr1=array();
                $arr1[]=$processData[$i];
                $arr1[]=$processData[$i+1];
                $allarr[]=$arr1;
            }
        }
        $this->assign('processList',$allarr);
        $this->assign('lists',$lists);
        $this->assign('news',$news);
        $this->assign('designer',$designer);
        $this->assign('cate_id',$cate);
        $this->assign('lunbo',$lunbo);
        $this->assign('common',$foot);
        return $this->fetch();
    }


    public function massage($id){
        if ($this->request->isPost()){
            $post = input('post.');
            $validate = $this->validate($post,'app\mobile\validate\Massage');
            if (true !== $validate){
                return json(['code'=>0,'msg'=>$validate]);
            }
            $data = [
                'username'=>$post['username'],
                'telephone'=>$post['telephone'],
                'wechat'=>$post['wechat'],
                'email'=>$post['email'],
                'content'=>$post['content']
            ];
            $ret = LeaveWord::create($data);
            if (!$ret){
                return json(['code'=>0,'msg'=>'提交失败']);
            }
            return json(['code'=>1,'msg'=>'提交成功']);
        }
        $lunbo = LunboList::where('category_id',$id)->order('sort desc')->select();
        $foot = CommonInfo::where('id',1)->find();
        $cate = CategoryList::order('sort desc')->select()->toArray();
        $this->assign('lunbo',$lunbo);
        $this->assign('cate',$cate);
        $this->assign('cate_id',$id);
        $this->assign('common',$foot);
        return $this->fetch();
    }
}